<template>
  <view class="rich-details">
    <Header :title="currentAgreement.title" :is-box-shadow="false" />
    <TRichText :content="currentAgreement.content" />
  </view>
</template>


<script setup lang="ts">
import Header from '@/components/Header/index.vue';
import TRichText from '@/components/TRichText/index.vue';
import { 
  electronicAgreement, 
  fraudPreventionNotice, 
  terminationAgreement, 
  salesServiceAgreement, 
  networkEntryAgreement, 
  privacyPolicy 
} from './index';
import { onLoad } from '@/router';
import { ref } from 'vue';

// 定义路由参数类型，与调用页面保持一致
type AgreementParams = {
  type?: string;
};

// 存储路由参数
const param = ref<AgreementParams>({});

// 定义当前显示的协议内容
const currentAgreement = ref(electronicAgreement); // 默认显示电子渠道开户服务协议

// 使用onLoad钩子接收路由参数
onLoad<'cardActivityAgreement'>(async (op) => {
  param.value = op;
  console.log('接收到的路由参数:', op);
  // 根据type参数加载不同的协议内容
  if (op.type) {
    console.log(`正在加载协议类型: ${op.type}`);
    
    // 根据type参数选择对应的协议内容
    switch(op.type) {
      case 'electronicAgreement':
        currentAgreement.value = electronicAgreement;
        break;
      case 'fraudPreventionNotice':
        currentAgreement.value = fraudPreventionNotice;
        break;
      case 'terminationAgreement':
        currentAgreement.value = terminationAgreement;
        break;
      case 'salesServiceAgreement':
        currentAgreement.value = salesServiceAgreement;
        break;
      case 'networkEntryAgreement':
        currentAgreement.value = networkEntryAgreement;
        break;
      case 'privacyPolicy':
        currentAgreement.value = privacyPolicy;
        break;
      default:
        currentAgreement.value = electronicAgreement; // 默认显示
        break;
    }
  }
});
</script>

<style lang="scss" scoped>
.rich-details {
  padding: 10rpx 0;
  min-height: 100vh;
  background-color: #fff;
}
</style>